package com.ruoyi.report_jl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_jl.domain.bo.ReportJlKfsfsysxfjlbBsInfoBo;
import com.ruoyi.report_jl.domain.vo.ReportJlKfsfsysxfjlbBsInfoVo;
import com.ruoyi.report_jl.domain.ReportJlKfsfsysxfjlbBsInfo;
import com.ruoyi.report_jl.mapper.ReportJlKfsfsysxfjlbBsInfoMapper;
import com.ruoyi.report_jl.service.IReportJlKfsfsysxfjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 矿粉筛分试验检测记录（水洗法）Service业务层处理
 *
 * @author tll
 * @date 2024-06-27
 */
@RequiredArgsConstructor
@Service
public class ReportJlKfsfsysxfjlbBsInfoServiceImpl implements IReportJlKfsfsysxfjlbBsInfoService {

    private final ReportJlKfsfsysxfjlbBsInfoMapper baseMapper;

    /**
     * 查询矿粉筛分试验检测记录（水洗法）
     */
    @Override
    @FIllBasicInfo
    public ReportJlKfsfsysxfjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询矿粉筛分试验检测记录（水洗法）列表
     */
    @Override
    public TableDataInfo<ReportJlKfsfsysxfjlbBsInfoVo> queryPageList(ReportJlKfsfsysxfjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportJlKfsfsysxfjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportJlKfsfsysxfjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询矿粉筛分试验检测记录（水洗法）列表
     */
    @Override
    public List<ReportJlKfsfsysxfjlbBsInfoVo> queryList(ReportJlKfsfsysxfjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportJlKfsfsysxfjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportJlKfsfsysxfjlbBsInfo> buildQueryWrapper(ReportJlKfsfsysxfjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportJlKfsfsysxfjlbBsInfo> lqw = Wrappers.lambdaQuery();
//        lqw.eq(bo.getTotalPage() != null, ReportJlKfsfsysxfjlbBsInfo::getTotalPage, bo.getTotalPage());
//        lqw.eq(bo.getPage() != null, ReportJlKfsfsysxfjlbBsInfo::getPage, bo.getPage());
//        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportJlKfsfsysxfjlbBsInfo::getJilbh, bo.getJilbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportJlKfsfsysxfjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportJlKfsfsysxfjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportJlKfsfsysxfjlbBsInfo::getYangpmc, bo.getYangpmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportJlKfsfsysxfjlbBsInfo::getYangpbh, bo.getYangpbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportJlKfsfsysxfjlbBsInfo::getYangpsl, bo.getYangpsl());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportJlKfsfsysxfjlbBsInfo::getYangpzt, bo.getYangpzt());
//        lqw.eq(bo.getYangpsj() != null, ReportJlKfsfsysxfjlbBsInfo::getYangpsj, bo.getYangpsj());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportJlKfsfsysxfjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportJlKfsfsysxfjlbBsInfo::getShiytjwd, bo.getShiytjwd());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportJlKfsfsysxfjlbBsInfo::getShiytjsd, bo.getShiytjsd());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportJlKfsfsysxfjlbBsInfo::getJiancyj, bo.getJiancyj());
//        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportJlKfsfsysxfjlbBsInfo::getPandyj, bo.getPandyj());
//        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportJlKfsfsysxfjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportJlKfsfsysxfjlbBsInfo::getFujsm, bo.getFujsm());
//        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportJlKfsfsysxfjlbBsInfo::getBaobmc, bo.getBaobmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportJlKfsfsysxfjlbBsInfo::getBaobbh, bo.getBaobbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportJlKfsfsysxfjlbBsInfo::getGongcmc, bo.getGongcmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportJlKfsfsysxfjlbBsInfo::getJiancr, bo.getJiancr());
//        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportJlKfsfsysxfjlbBsInfo::getJilr, bo.getJilr());
//        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportJlKfsfsysxfjlbBsInfo::getFuhr, bo.getFuhr());
//        lqw.eq(bo.getRiq() != null, ReportJlKfsfsysxfjlbBsInfo::getRiq, bo.getRiq());
//        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportJlKfsfsysxfjlbBsInfo::getShebIds, bo.getShebIds());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportJlKfsfsysxfjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
//        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportJlKfsfsysxfjlbBsInfo::getPandyjIds, bo.getPandyjIds());
//        lqw.eq(StringUtils.isNotBlank(bo.getChenglcsItem1()), ReportJlKfsfsysxfjlbBsInfo::getChenglcsItem1, bo.getChenglcsItem1());
//        lqw.eq(StringUtils.isNotBlank(bo.getChenglcsItem2()), ReportJlKfsfsysxfjlbBsInfo::getChenglcsItem2, bo.getChenglcsItem2());
//        lqw.eq(StringUtils.isNotBlank(bo.getChenglcsItem3()), ReportJlKfsfsysxfjlbBsInfo::getChenglcsItem3, bo.getChenglcsItem3());
//        lqw.eq(bo.getShiyzbzlItem1() != null, ReportJlKfsfsysxfjlbBsInfo::getShiyzbzlItem1, bo.getShiyzbzlItem1());
//        lqw.eq(bo.getShiyzbzlItem2() != null, ReportJlKfsfsysxfjlbBsInfo::getShiyzbzlItem2, bo.getShiyzbzlItem2());
//        lqw.eq(bo.getShiyzbzlItem3() != null, ReportJlKfsfsysxfjlbBsInfo::getShiyzbzlItem3, bo.getShiyzbzlItem3());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiyzlGroup1()), ReportJlKfsfsysxfjlbBsInfo::getShiyzlGroup1, bo.getShiyzlGroup1());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiyzlGroup2()), ReportJlKfsfsysxfjlbBsInfo::getShiyzlGroup2, bo.getShiyzlGroup2());
//        lqw.eq(bo.getShaikccItem1() != null, ReportJlKfsfsysxfjlbBsInfo::getShaikccItem1, bo.getShaikccItem1());
//        lqw.eq(bo.getShaiszGroup1Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup1Item1, bo.getShaiszGroup1Item1());
//        lqw.eq(bo.getFenjsyGroup1Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup1Item1, bo.getFenjsyGroup1Item1());
//        lqw.eq(bo.getLeijsyGroup1Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup1Item1, bo.getLeijsyGroup1Item1());
//        lqw.eq(bo.getTonggbflGroup1Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup1Item1, bo.getTonggbflGroup1Item1());
//        lqw.eq(bo.getShaiszGroup2Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup2Item1, bo.getShaiszGroup2Item1());
//        lqw.eq(bo.getFenjsyGroup2Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup2Item1, bo.getFenjsyGroup2Item1());
//        lqw.eq(bo.getLeijsyGroup2Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup2Item1, bo.getLeijsyGroup2Item1());
//        lqw.eq(bo.getTonggbflGroup2Item1() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup2Item1, bo.getTonggbflGroup2Item1());
//        lqw.eq(bo.getTonggbflPjzItem1() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflPjzItem1, bo.getTonggbflPjzItem1());
//        lqw.eq(bo.getShaikccItem2() != null, ReportJlKfsfsysxfjlbBsInfo::getShaikccItem2, bo.getShaikccItem2());
//        lqw.eq(bo.getShaiszGroup1Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup1Item2, bo.getShaiszGroup1Item2());
//        lqw.eq(bo.getFenjsyGroup1Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup1Item2, bo.getFenjsyGroup1Item2());
//        lqw.eq(bo.getLeijsyGroup1Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup1Item2, bo.getLeijsyGroup1Item2());
//        lqw.eq(bo.getTonggbflGroup1Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup1Item2, bo.getTonggbflGroup1Item2());
//        lqw.eq(bo.getShaiszGroup2Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup2Item2, bo.getShaiszGroup2Item2());
//        lqw.eq(bo.getFenjsyGroup2Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup2Item2, bo.getFenjsyGroup2Item2());
//        lqw.eq(bo.getLeijsyGroup2Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup2Item2, bo.getLeijsyGroup2Item2());
//        lqw.eq(bo.getTonggbflGroup2Item2() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup2Item2, bo.getTonggbflGroup2Item2());
//        lqw.eq(bo.getTonggbflPjzItem2() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflPjzItem2, bo.getTonggbflPjzItem2());
//        lqw.eq(bo.getShaikccItem3() != null, ReportJlKfsfsysxfjlbBsInfo::getShaikccItem3, bo.getShaikccItem3());
//        lqw.eq(bo.getShaiszGroup1Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup1Item3, bo.getShaiszGroup1Item3());
//        lqw.eq(bo.getFenjsyGroup1Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup1Item3, bo.getFenjsyGroup1Item3());
//        lqw.eq(bo.getLeijsyGroup1Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup1Item3, bo.getLeijsyGroup1Item3());
//        lqw.eq(bo.getTonggbflGroup1Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup1Item3, bo.getTonggbflGroup1Item3());
//        lqw.eq(bo.getShaiszGroup2Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup2Item3, bo.getShaiszGroup2Item3());
//        lqw.eq(bo.getFenjsyGroup2Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup2Item3, bo.getFenjsyGroup2Item3());
//        lqw.eq(bo.getLeijsyGroup2Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup2Item3, bo.getLeijsyGroup2Item3());
//        lqw.eq(bo.getTonggbflGroup2Item3() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup2Item3, bo.getTonggbflGroup2Item3());
//        lqw.eq(bo.getTonggbflPjzItem3() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflPjzItem3, bo.getTonggbflPjzItem3());
//        lqw.eq(bo.getShaikccItem4() != null, ReportJlKfsfsysxfjlbBsInfo::getShaikccItem4, bo.getShaikccItem4());
//        lqw.eq(bo.getShaiszGroup1Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup1Item4, bo.getShaiszGroup1Item4());
//        lqw.eq(bo.getFenjsyGroup1Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup1Item4, bo.getFenjsyGroup1Item4());
//        lqw.eq(bo.getLeijsyGroup1Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup1Item4, bo.getLeijsyGroup1Item4());
//        lqw.eq(bo.getTonggbflGroup1Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup1Item4, bo.getTonggbflGroup1Item4());
//        lqw.eq(bo.getShaiszGroup2Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup2Item4, bo.getShaiszGroup2Item4());
//        lqw.eq(bo.getFenjsyGroup2Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup2Item4, bo.getFenjsyGroup2Item4());
//        lqw.eq(bo.getLeijsyGroup2Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup2Item4, bo.getLeijsyGroup2Item4());
//        lqw.eq(bo.getTonggbflGroup2Item4() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup2Item4, bo.getTonggbflGroup2Item4());
//        lqw.eq(bo.getTonggbflPjzItem4() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflPjzItem4, bo.getTonggbflPjzItem4());
//        lqw.eq(bo.getShaikccItem5() != null, ReportJlKfsfsysxfjlbBsInfo::getShaikccItem5, bo.getShaikccItem5());
//        lqw.eq(bo.getShaiszGroup1Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup1Item5, bo.getShaiszGroup1Item5());
//        lqw.eq(bo.getFenjsyGroup1Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup1Item5, bo.getFenjsyGroup1Item5());
//        lqw.eq(bo.getLeijsyGroup1Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup1Item5, bo.getLeijsyGroup1Item5());
//        lqw.eq(bo.getTonggbflGroup1Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup1Item5, bo.getTonggbflGroup1Item5());
//        lqw.eq(bo.getShaiszGroup2Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup2Item5, bo.getShaiszGroup2Item5());
//        lqw.eq(bo.getFenjsyGroup2Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup2Item5, bo.getFenjsyGroup2Item5());
//        lqw.eq(bo.getLeijsyGroup2Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup2Item5, bo.getLeijsyGroup2Item5());
//        lqw.eq(bo.getTonggbflGroup2Item5() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup2Item5, bo.getTonggbflGroup2Item5());
//        lqw.eq(bo.getTonggbflPjzItem5() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflPjzItem5, bo.getTonggbflPjzItem5());
//        lqw.eq(bo.getShaikccItem6() != null, ReportJlKfsfsysxfjlbBsInfo::getShaikccItem6, bo.getShaikccItem6());
//        lqw.eq(bo.getShaiszGroup1Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup1Item6, bo.getShaiszGroup1Item6());
//        lqw.eq(bo.getFenjsyGroup1Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup1Item6, bo.getFenjsyGroup1Item6());
//        lqw.eq(bo.getLeijsyGroup1Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup1Item6, bo.getLeijsyGroup1Item6());
//        lqw.eq(bo.getTonggbflGroup1Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup1Item6, bo.getTonggbflGroup1Item6());
//        lqw.eq(bo.getShaiszGroup2Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getShaiszGroup2Item6, bo.getShaiszGroup2Item6());
//        lqw.eq(bo.getFenjsyGroup2Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getFenjsyGroup2Item6, bo.getFenjsyGroup2Item6());
//        lqw.eq(bo.getLeijsyGroup2Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getLeijsyGroup2Item6, bo.getLeijsyGroup2Item6());
//        lqw.eq(bo.getTonggbflGroup2Item6() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflGroup2Item6, bo.getTonggbflGroup2Item6());
//        lqw.eq(bo.getTonggbflPjzItem6() != null, ReportJlKfsfsysxfjlbBsInfo::getTonggbflPjzItem6, bo.getTonggbflPjzItem6());
        return lqw;
    }

    /**
     * 新增矿粉筛分试验检测记录（水洗法）
     */
    @Override
    public Boolean insertByBo(ReportJlKfsfsysxfjlbBsInfoBo bo) {
        ReportJlKfsfsysxfjlbBsInfo add = BeanUtil.toBean(bo, ReportJlKfsfsysxfjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改矿粉筛分试验检测记录（水洗法）
     */
    @Override
    public Boolean updateByBo(ReportJlKfsfsysxfjlbBsInfoBo bo) {
        ReportJlKfsfsysxfjlbBsInfo update = BeanUtil.toBean(bo, ReportJlKfsfsysxfjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportJlKfsfsysxfjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除矿粉筛分试验检测记录（水洗法）
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
